#include <gtk/gtk.h>
#include "GTKIPV6.h"

int main (int argc, char *argv[])
{
  GtkWidget *button = NULL;
  GtkWidget *win = NULL;
  GtkWidget *vbox = NULL;
  GtkWidget *hbox1 = NULL;
  GtkWidget *hbox2 = NULL;
  //GtkWidget *hbox3 = NULL;
  //GtkWidget *menubar = NULL;
  GtkWidget *h = NULL;
  GtkWidget *label = NULL;
  GError *err[100];

  /* Initialize GTK+ */
  g_log_set_handler ("Gtk", G_LOG_LEVEL_WARNING, (GLogFunc) gtk_false, NULL);
  gtk_init (&argc, &argv);
  g_log_set_handler ("Gtk", G_LOG_LEVEL_WARNING, g_log_default_handler, NULL);

  /* Create the main window */
  win = gtk_window_new (GTK_WINDOW_TOPLEVEL);
  gtk_container_set_border_width (GTK_CONTAINER (win), 13);
  gtk_window_set_title (GTK_WINDOW (win), "GIPV6");
  gtk_window_set_position (GTK_WINDOW (win), GTK_WIN_POS_CENTER);
  gtk_window_set_resizable( GTK_WINDOW(win), FALSE );
  gtk_window_set_default_icon_from_file("/usr/share/icons/hicolor/48x48/apps/fedora-logo-icon.png", err);
  gtk_widget_realize (win);
  g_signal_connect (win, "destroy", gtk_main_quit, NULL);

  /* Create a vertical box with buttons */
  vbox = gtk_vbox_new (FALSE, 5);
  gtk_container_add (GTK_CONTAINER (win), vbox);

  //menubar = gtk_menu_bar_new();
  //gtk_container_add(GTK_CONTAINER(win), hbox);

  hbox1 = gtk_hbox_new(FALSE, 5);
  gtk_container_add(GTK_CONTAINER(vbox), hbox1);

  label = gtk_label_new("IPV6隧道任务：");
  gtk_label_set_justify(GTK_LABEL(label), GTK_JUSTIFY_LEFT);
  gtk_box_pack_start (GTK_BOX (hbox1), label, FALSE, TRUE, 0);

  hbox2 = gtk_hbox_new(TRUE, 8);
  gtk_container_add(GTK_CONTAINER(vbox), hbox2);

  button = gtk_button_new_from_stock ("启动隧道(_S)");
  g_signal_connect (G_OBJECT (button), "clicked", G_CALLBACK (gipv6_start), (gpointer) win);
  gtk_box_pack_start (GTK_BOX (hbox2), button, TRUE, TRUE, 0);

  button = gtk_button_new_from_stock ("停止隧道(_T)");
  g_signal_connect (G_OBJECT (button), "clicked", G_CALLBACK (gipv6_stop), (gpointer) win);
  gtk_box_pack_start (GTK_BOX (hbox2), button, TRUE, TRUE, 0);

  button = gtk_button_new_from_stock ("重新连接(_R)");
  g_signal_connect (G_OBJECT (button), "clicked", G_CALLBACK (gipv6_rexec), (gpointer) win);
  gtk_box_pack_start (GTK_BOX (hbox2), button, TRUE, TRUE, 0);

  button = gtk_button_new_from_stock ("强制关闭(_K)");
  g_signal_connect (G_OBJECT (button), "clicked", G_CALLBACK (gipv6_kill), (gpointer) win);
  gtk_box_pack_start (GTK_BOX (hbox2), button, TRUE, TRUE, 0);

  //h = gtk_hseparator_new();
  //gtk_box_pack_start(GTK_BOX(vbox), h, TRUE, TRUE, 0);

  button = gtk_button_new_from_stock ("状态(_N)");
  g_signal_connect (G_OBJECT (button), "clicked", G_CALLBACK (miredo_), (gpointer) win);
  gtk_box_pack_start (GTK_BOX (hbox2), button, TRUE, TRUE, 0);

  //hbox1 = gtk_hbox_new (TRUE,10);
  //gtk_container_add(GTK_CONTAINER(vbox), hbox1);

  h = gtk_expander_new("高级任务");
  gtk_box_pack_start(GTK_BOX(vbox), h, TRUE, TRUE, 0);

  hbox2 = gtk_hbox_new(TRUE,10);
  gtk_container_add(GTK_CONTAINER(h), hbox2);

  button = gtk_button_new_from_stock ("还原Hosts(_P)");
  g_signal_connect (G_OBJECT (button), "clicked", G_CALLBACK (hosts_prep), (gpointer) win);
  gtk_box_pack_start (GTK_BOX (hbox2), button, TRUE, TRUE, 0);

  //h = gtk_hseparator_new();
  //gtk_box_pack_start(GTK_BOX(vbox), h, TRUE, TRUE, 0);

  button = gtk_button_new_from_stock("配置文件(_A)");
  g_signal_connect( G_OBJECT(button), "clicked", G_CALLBACK(conf_file), (gpointer) win);
  gtk_box_pack_start( GTK_BOX(hbox2), button, TRUE, TRUE, 0);

  button = gtk_button_new_from_stock (GTK_STOCK_ABOUT);
  g_signal_connect (G_OBJECT (button), "clicked", G_CALLBACK (gipv6_info), (gpointer) win);
  gtk_box_pack_start (GTK_BOX (hbox2), button, TRUE, TRUE, 0);

  button = gtk_button_new_from_stock (GTK_STOCK_CLOSE);
  g_signal_connect (button, "clicked", gtk_main_quit, NULL);
  gtk_box_pack_start (GTK_BOX (hbox2), button, TRUE, TRUE, 0);

  /* Enter the main loop */
  gtk_widget_show_all (win);
  gtk_main ();
  return 0;
}
